package com.sysu.simulation.helper;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;

import java.util.List;

public class ApiHelper {
    public static void login(String uid, String pwd, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("id", uid);
        params.put("password", pwd);
        SimHttpClient.post("api/login", params, handler);
    }

    public static void register(String uid, String pwd, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("id", uid);
        params.put("password", pwd);
        SimHttpClient.post("api/reg", params, handler);
    }

    public static void editInfo(String info, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("info", info);
        SimHttpClient.post("api/uu", params, handler);
    }

    public static void getUserClothes(String uid, int nextItem, TextHttpResponseHandler handler) {
        if(uid==null || TextUtils.isEmpty(uid)) return;
        RequestParams params = new RequestParams();
        params.put("id", uid);
        params.put("nextItem", nextItem);
        SimHttpClient.get("api/gc", params, handler);
    }

    public static void deleteUserClothes(String uid, List<String> all_clothes, TextHttpResponseHandler handler) {
        if(uid==null || TextUtils.isEmpty(uid)) return;
        RequestParams params = new RequestParams();
        params.put("id", uid);
        params.put("name", new Gson().toJson(all_clothes));
        SimHttpClient.post("api/dmc", params, handler);
    }

    public static void addUserClothes(String uid, String clothes, TextHttpResponseHandler handler) {
        if(uid==null || TextUtils.isEmpty(uid)) return;
        RequestParams params = new RequestParams();
        params.put("id", uid);
        params.put("info", clothes);
        SimHttpClient.post("api/ac", params, handler);
    }

    public static void editUserClothes(String uid, String clothes, TextHttpResponseHandler handler) {
        if(uid==null || TextUtils.isEmpty(uid)) return;
        RequestParams params = new RequestParams();
        params.put("id", uid);
        params.put("info", clothes);
        SimHttpClient.post("api/uc", params, handler);
    }

    public static void sim(String uid, String datas, TextHttpResponseHandler handler) {
        if(uid==null || TextUtils.isEmpty(uid)) return;
        if(datas == null || TextUtils.isEmpty(datas)) return;
        RequestParams params = new RequestParams();
        params.put("id", uid);
        params.put("params", datas);
        SimHttpClient.post("api/sim", params, handler);
    }

    public static void getRecords(String uid, TextHttpResponseHandler handler) {
        if(uid==null || TextUtils.isEmpty(uid)) return;
        RequestParams params = new RequestParams();
        params.put("id", uid);
        SimHttpClient.post("api/gr", params, handler);
    }
}
